
#region Using Statements
using System.Diagnostics;
using System.Windows.Forms;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
#endregion

namespace WinFormsGraphicsDevice
{
    public class LevelEditor : GraphicsDeviceControl
    {
        Stopwatch timer;
        ContentManager content;
        SpriteBatch spriteBatch;
        SpriteFont font;
        Camera camera;
        int tileX;
        int tileY;

        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void Initialize()
        {
            camera = new Camera();

            content = new ContentManager(Services, "Content");

            font = content.Load<SpriteFont>("text");

            // Start the animation timer.
            timer = Stopwatch.StartNew();

            spriteBatch = new SpriteBatch(GraphicsDevice);


            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };
        }

        public void MoveMap(float dx, float dy)
        {
            camera.X += dx;
            camera.Y += dy;
        }

        /// <summary>
        /// Draws the control.
        /// </summary>
        /// 
        protected override void Draw()
        {
            GraphicsDevice.Clear(Color.Gray);

            // Spin the triangle according to how much time has passed.
            float time = (float)timer.Elapsed.TotalSeconds;

            spriteBatch.Begin();

            spriteBatch.DrawString(font, string.Format("Tile Mouse Coord ({0},{1})", tileX, tileY), Vector2.Zero, Color.White);

            spriteBatch.End();
        }

        public void SetTile(string tileType)
        {
        }

        /// <summary>
        /// Select a tile
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {        
            base.OnMouseMove(e);
        }

        public void Export(string filename)
        {
        }

        public void Import(string filename)
        {
        }

        public void SetMapSize(int x, int y)
        {
        }
    }

    public class Camera
    {
        Vector2 position = new Vector2();

        public float X
        {
            get { return this.position.X; }
            set { this.position.X = value; }
        }

        public float Y
        {
            get { return this.position.Y; }
            set { this.position.Y = value; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
    }
}
